package com.oop.lsp;

import org.junit.Test;

public class LspTest {
	/**
	 * 测试违反LSP
	 */
	@Test
	public void testLspViolate() {
		Client client = new Client();
		Base base = new Base();
		Base derived = new Derived();
		client.lspViolate(base);

		// 当用派生类对象替换基类对象时，发生AssertError 说明违反了LSP原则，因为派生类的方法前置条件比基类更加严格了
		client.lspViolate(derived);
	}

	/**
	 * 测试遵循LSP
	 */
	@Test
	public void testLspFollow() {
		Client client = new Client();
		Base base = new Base();
		Base derived = new Derived();
		client.lspFollow(base);
		client.lspFollow(derived);
	}
}
